import { combineReducers, configureStore } from '@reduxjs/toolkit'
import articleSlice from './modules/articleSlice'
import languageSlice from './modules/languageSlice'
import themeSlice from './modules/ThemeSlice'
import userSlice from './modules/userSlice'
import { persistReducer, persistStore } from 'redux-persist'
import storage from 'redux-persist/lib/storage'
// 将所有的slice合并形成最终的根切片
const rootReducer = combineReducers({
  userSlice,
  articleSlice,
  languageSlice,
  themeSlice
})

// reducer持久化配置
const persistConfig = {
  key: 'root',  // 表示 存储key
  storage: storage,  // 表示存储方式,持久化的方式
  // whitelist: [], // 需要持久化保存的模块，默认保存所有模块（语义：白名单）
  // blacklist: ["counterSlice"], // 不需要持久化保存的模块，默认不保存任何模块（语义：黑名单）
}

// 对reducer进行持久化
const persistedReducer = persistReducer(persistConfig,rootReducer)


const store = configureStore({
  reducer:persistedReducer,
  middleware(getDefaultMiddleware) {
    return getDefaultMiddleware({
      serializableCheck: false,
    })
  },
})


// 对store进行持久化
const persistedStore = persistStore(store)

export {
  persistedStore, store
}

